package org.pixelhead.framework;

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.geom.Matrix;

class PixelHeadGame extends Bitmap
{
	public var zoomFactor:Float;
	public var backgroundColor:UInt;
	private var graphics:BitmapData;
	private var renderQueue:Array<DisplayObject>;
	public function new(width:Int, height:Int, backgroundColor:UInt, ?zoomFactor:Float = 1)
	{
		graphics = new BitmapData(Std.int(width/zoomFactor), Std.int(height/zoomFactor), false, backgroundColor);
		super(graphics);
		this.width = width;
		this.height = height;
		renderQueue = new Array();
	}
	public function removeFromRenderQueue(id:Int):Void
	{
		renderQueue.splice(id, 1);
	}
	public function getItemFromRenderQueue(id:Int):DisplayObject
	{
		return renderQueue[id];
	}
	public function addToRenderQueue(item:DisplayObject):Int
	{
		renderQueue.push(item);
		return renderQueue.length-1;
	}
	public function render():Void
	{
		graphics.fillRect(graphics.rect, backgroundColor);
		var mtr:Matrix = new Matrix();
		for(i in renderQueue)
		{
			mtr.tx = i.x;
			mtr.ty = i.y;
			graphics.draw(i, mtr);
		}
	}
}
